local M = {}

local barStyles = require("widgets.progressStyle")

function M.newProgressBar(params)
	local gProgress = display.newGroup()
	gProgress.anchorChildren = true

	local bg = display.newRect(0, 0, 90, 7)
	bg:setFillColor(0, 0, 0, 0.8)
	gProgress:insert(bg)
	layout.setAnchor(bg, 0, 0.5)

	local imgPath = barStyles.styles[1].barPath

	local img = imgTool.newImageRect({
		path = imgPath,
		parent = gProgress,
		width = bg.width - 4, height = bg.height - 2,
		x = bg.x, y = bg.y
	})
	layout.setAnchor(img, 0, 0.5)

	function gProgress:setPercent(percent, time, onComplete)
		percent = math.max(percent, 0.0001)
		transition.to(img, {time = time, xScale = percent, onComplete = onComplete})
	end

	return gProgress
end

return M